import connDB


def getDataNum(schema,conn):
    if conn:
        with open("read/批量建表.csv", "r", encoding='utf8') as csv:
            with open("out/表数据量.csv", "w", encoding='utf8') as out:
                for line in csv:
                    tableName = line.strip()
                    query = f"select count(*) from {schema}.{tableName};"
                    dataNum = connDB.fetch_data(conn, query)
                    if dataNum:
                        out.write(f"{tableName},{dataNum[0][0]}\n")
                        print(f"{tableName} \t\t数据量:{dataNum[0][0]}条")

if __name__ == "__main__":
    schema = 'dt_yunnan'
    #数据库连接
    conn = connDB.create_connection(**connDB.dm_prd_config)
    getDataNum(schema,conn)
